import java.util.ArrayList;
import java.util.List;

/**
 * @program: leetcode006
 * @author: JCM
 * @create: 2022-11-20 14:03
 * @description:
 **/
public class leetCode006 {
    public static void main(String[] args) {
        String s = "PAYPALISHIRING";
        int numRows = 3;
        String ans = convert(s,numRows);
    }

    //
    private static String convert(String s, int numRows) {
        if (numRows < 2) return s;
        List<StringBuffer> list = new ArrayList<>();
        for (int i = 0; i < numRows; i++) {
            list.add(new StringBuffer());
        }
        int i = 0;int flag = -1;
        for(char ch : s.toCharArray()) {
            list.get(i).append(ch);
            if(i == 0 || i == numRows-1) flag = -flag;
            i += flag;
        }
        StringBuffer res = new StringBuffer();
        for (StringBuffer sb : list) res.append(sb);
        return res.toString();
    }
}
